package com.learn.english.controller;

import com.learn.english.domain.PageQueryDTO;
import com.learn.english.domain.R;
import com.learn.english.model.entity.User;
import com.learn.english.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author TISNIW
 * @version 1.0
 * @date 2025/6/16 11:08
 * @desc 用户管理控制器
 */
@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Autowired
    private IUserService userService;

    /**
     * 获取用户列表（分页）
     */
    @GetMapping("/list")
    public R getUserList(PageQueryDTO queryDTO) {
        return userService.getUserList(queryDTO);
    }

    /**
     * 获取用户详情
     */
    @GetMapping("/{id}")
    public R getUserDetail(@PathVariable Long id) {
        return userService.getUserDetail(id);
    }

    /**
     * 添加用户
     */
    @PostMapping("/add")
    public R addUser(@RequestBody User user) {
        return userService.addUser(user);
    }

    /**
     * 更新用户信息
     */
    @PostMapping("/update")
    public R updateUser(@RequestBody User user) {
        return userService.updateUser(user);
    }

    /**
     * 更新用户状态
     */
    @PostMapping("/status")
    public R updateUserStatus(@RequestParam Long id, @RequestParam Byte status) {
        return userService.updateUserStatus(id, status);
    }

    /**
     * 重置用户密码
     */
    @PostMapping("/resetPassword")
    public R resetPassword(@RequestParam Long id, @RequestParam String newPassword) {
        return userService.resetPassword(id, newPassword);
    }

    /**
     * 删除用户
     */
    @PostMapping("/delete/{id}")
    public R deleteUser(@PathVariable Long id) {
        return userService.deleteUser(id);
    }

    /**
     * 批量删除用户
     */
    @PostMapping("/batchDelete")
    public R batchDeleteUsers(@RequestBody List<Long> ids) {
        return userService.batchDeleteUsers(ids);
    }

    /**
     * 批量更新用户状态
     */
    @PostMapping("/batchStatus")
    public R batchUpdateUserStatus(@RequestParam List<Long> ids, @RequestParam Byte status) {
        return userService.batchUpdateUserStatus(ids, status);
    }

    /**
     * 搜索用户
     */
    @GetMapping("/search")
    public R searchUsers(PageQueryDTO queryDTO) {
        return userService.searchUsers(queryDTO);
    }
}
